package jge.window.impl;

import java.awt.Component;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import jge.window.JGEWindow;
import jge.window.JGEWindowFactory.WINDOWAPI;

/**
 * @author Sam Pengilly
 *
 */
public class AWTWindow implements JGEWindow {
	Frame frame;
	GraphicsDevice graphicsDevice;
	//AWTWindowListener windowListener = new AWTWindow.AWTWindowListener();
	
	public AWTWindow(String title, int width, int height, boolean full) {
		this.frame = new Frame();
		this.frame.setSize(width, height);
		this.frame.setTitle(title);
		//this.frame.setVisible(true);
		//this.frame.addWindowListener(this.windowListener);
		
		GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
		this.graphicsDevice = gEnv.getDefaultScreenDevice();
		
		if (full) {
			this.setFullScreen(full);
		}
	}
	
	@Override
	public void add(Component comp) {
		this.frame.add(comp);
	}

	@Override
	public void setFullScreen(boolean enable) {
		if (this.graphicsDevice.isFullScreenSupported()) {
			if (enable) {
				this.graphicsDevice.setFullScreenWindow(this.frame);
			} else {
				this.graphicsDevice.setFullScreenWindow(null);
			}
		}
	}

	@Override
	public void setSize(int width, int height) {
		this.frame.setSize(width, height);
	}
	
	@Override
	public void setVisible(boolean visible) {
		this.frame.setVisible(visible);
	}

	@Override
	public int getWidth() {
		return this.frame.getWidth();
	}

	@Override
	public int getHeight() {
		return this.frame.getHeight();
	}

	@Override
	public boolean getFullScreen() {
		return this.graphicsDevice.getFullScreenWindow() == this.frame ? true : false;
	}

	@Override
	public WINDOWAPI getApiType() {
		return WINDOWAPI.AWT;
	}
	
//	/**
//	 * @return the windowListener
//	 */
//	public EventListener getWindowListener() {
//		return windowListener;
//	}
//
//	/**
//	 * Implementation of the Window Event Listener for AWT Windows
//	 * @author Sam
//	 */
//	protected class AWTWindowListener implements WindowListener {
//
//		Command windowActivatedCommand;
//		Command windowClosedCommand;
//		Command windowClosingCommand;
//		Command windowDeactivatedCommand;
//		Command windowDeiconifiedCommand;
//		Command windowIconifiedCommand;
//		Command windowOpenedCommand;
//		
//		@Override
//		public void windowActivated(WindowEvent arg0) {
//			if (this.windowActivatedCommand != null) {
//				this.windowActivatedCommand.execute();
//			}
//		}
//
//		@Override
//		public void windowClosed(WindowEvent arg0) {
//			if (this.windowClosedCommand != null) {
//				this.windowClosedCommand.execute();
//			}
//		}
//
//		@Override
//		public void windowClosing(WindowEvent arg0) {
//			if (this.windowClosingCommand != null) {
//				this.windowClosingCommand.execute();
//			}
//		}
//
//		@Override
//		public void windowDeactivated(WindowEvent arg0) {
//			if (this.windowDeactivatedCommand != null) {
//				this.windowDeactivatedCommand.execute();
//			}
//		}
//
//		@Override
//		public void windowDeiconified(WindowEvent arg0) {
//			if (this.windowDeiconifiedCommand != null) {
//				this.windowDeiconifiedCommand.execute();
//			}
//		}
//
//		@Override
//		public void windowIconified(WindowEvent arg0) {
//			if (this.windowIconifiedCommand != null) {
//				this.windowIconifiedCommand.execute();
//			}
//		}
//
//		@Override
//		public void windowOpened(WindowEvent arg0) {
//			if (this.windowOpenedCommand != null) {
//				this.windowOpenedCommand.execute();
//			}
//		}
//
//		/**
//		 * @param windowActivatedCommand the windowActivatedCommand to set
//		 */
//		public void setWindowActivatedCommand(Command windowActivatedCommand) {
//			this.windowActivatedCommand = windowActivatedCommand;
//		}
//
//		/**
//		 * @param windowClosedCommand the windowClosedCommand to set
//		 */
//		public void setWindowClosedCommand(Command windowClosedCommand) {
//			this.windowClosedCommand = windowClosedCommand;
//		}
//
//		/**
//		 * @param windowClosingCommand the windowClosingCommand to set
//		 */
//		public void setWindowClosingCommand(Command windowClosingCommand) {
//			this.windowClosingCommand = windowClosingCommand;
//		}
//
//		/**
//		 * @param windowDeactivatedCommand the windowDeactivatedCommand to set
//		 */
//		public void setWindowDeactivatedCommand(Command windowDeactivatedCommand) {
//			this.windowDeactivatedCommand = windowDeactivatedCommand;
//		}
//
//		/**
//		 * @param windowDeiconifiedCommand the windowDeiconifiedCommand to set
//		 */
//		public void setWindowDeiconifiedCommand(Command windowDeiconifiedCommand) {
//			this.windowDeiconifiedCommand = windowDeiconifiedCommand;
//		}
//
//		/**
//		 * @param windowIconifiedCommand the windowIconifiedCommand to set
//		 */
//		public void setWindowIconifiedCommand(Command windowIconifiedCommand) {
//			this.windowIconifiedCommand = windowIconifiedCommand;
//		}
//
//		/**
//		 * @param windowOpenedCommand the windowOpenedCommand to set
//		 */
//		public void setWindowOpenedCommand(Command windowOpenedCommand) {
//			this.windowOpenedCommand = windowOpenedCommand;
//		}
//		
//	}

}
